package org.wlc.demov1Impl;

import org.wlc.demov1.AuthService;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 王立朝
 * @date 2022/5/17
 * @description:
 */
public class AuthController {
    /**
     *  时间格式化
     */
    private SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public AuthInfo doAuth(String uid, String orderId, Date authDate) throws ParseException {
        // 三级审批
        Date date = AuthService.queryAuthInfo("1000013",orderId);
        if(null == date){
            return new AuthInfo("0001", "单号：", orderId, " 状态：待三级审批负责人 ", "王工");
        }
        // 二级审批
        if (authDate.after(f.parse("2022-05-01 00:00:00"))
                && authDate.before(f.parse("2022-05-25 23:59:59"))) {
            date = AuthService.queryAuthInfo("1000012", orderId);
            if (null == date) {
                return new AuthInfo("0001", "单号：", orderId, " 状态：待二级审批负责人 ", "张经理");
            }
        }
        // 一级审批
        if (authDate.after(f.parse("2022-05-11 00:00:00"))
                && authDate.before(f.parse("2022-05-20 23:59:59"))) {
            date = AuthService.queryAuthInfo("1000011", orderId);
            if (null == date) {
                return new AuthInfo("0001", "单号：", orderId, " 状态：待一级审批负责人 ", "段总");
            }
        }
        return new AuthInfo("0001", "单号：", orderId, " 状态：审批完成");
    }
}
